<?php
// | Copyright (c) 2014 xxyCms All rights reserved.
// +----------------------------------------------------------------------
// | Author: Hei Dousha
// +----------------------------------------------------------------------
// | date: 2015-1-14

/**
 * 上传文件，成功后返回文件ID数组
 * Enter description here ...
 * @param unknown_type $fieldName 文件字段名  默认图片img
 * @param unknown_type $savePath //子目录  默认Images文件夹
 * @param unknown_type $saveName //文件名
 * @param unknown_type $rootPath //根目录 默认 ./Uploads/
 */
function uploadFile($fieldName = 'img' ,$savePath = './Images/', $saveName = '', $rootPath = './Uploads/'){
    //类型是否在允许范围内
    $uploadType = C('UPLOAD_TYPE');
    	
    //文件大小检测
    $maxSize = C('UPLOAD_MAX_SIZE');
    	
    //开始上传
    $upload = new \Think\Upload();  // 实例化上传类
    $upload->maxSize   =      $maxSize ? $maxSize : 0;  // 设置附件上传大小,0为不限制
    $upload->exts      =     $uploadType ? $uploadType : array();  // 设置附件上传类型
    $upload->subName = ''; //子目录构建方式
    $rootPath = $rootPath ? $rootPath : C('UPLOAD_ROOTPATH');
    !empty($rootPath) && $upload->rootPath = $rootPath;  //根路径
    !empty($savePath) && $upload->savePath = $savePath;  // 设置附件上传目录(根路径下一级)
    !empty($saveName) && $upload->saveName = $saveName;
    $info   =   $upload->upload();
    if(!$info) {
    	return $upload->getError();
    }else{
    	return $info;
    }
}

